{% extends "base.html" %}

{% block title %}管理控制台 - 车辆管理系统{% endblock %}

{% block content %}
<h2 class="mb-4">管理控制台</h2>

<!-- 统计卡片 -->
<div class="row">
    <div class="col-md-3">
        <div class="card text-white bg-primary mb-4">
            <div class="card-body">
                <h5 class="card-title">当前停车车辆</h5>
                <h2 class="display-5">{{ active_count }}</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-white bg-success mb-4">
            <div class="card-body">
                <h5 class="card-title">今日收入</h5>
                <h2 class="display-5">¥{{ "%.2f"|format(today_income) }}</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-white bg-warning mb-4">
            <div class="card-body">
                <h5 class="card-title">停车场数量</h5>
                <h2 class="display-5">{{ parking_lots|length }}</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-white bg-danger mb-4">
            <div class="card-body">
                <h5 class="card-title">已注册车辆</h5>
                <h2 class="display-5">{{ vehicle_count }}</h2>
            </div>
        </div>
    </div>
</div>

<!-- 最近停车记录 -->
<div class="card mb-4">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">最近停车记录</h5>
        <a href="{{ url_for('admin_parking_records') }}" class="btn btn-sm btn-primary">查看所有记录</a>
    </div>
    <div class="card-body">
        {% if recent_records %}
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>车牌号</th>
                            <th>停车场</th>
                            <th>入场时间</th>
                            <th>出场时间</th>
                            <th>费用</th>
                            <th>状态</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for record in recent_records %}
                            <tr>
                                <td>{{ record.plate_number }}</td>
                                <td>{{ record.parking_lot_name }}</td>
                                <td>{{ record.entry_time.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                <td>
                                    {% if record.exit_time %}
                                        {{ record.exit_time.strftime('%Y-%m-%d %H:%M:%S') }}
                                    {% else %}
                                        <span class="badge bg-info">在场</span>
                                    {% endif %}
                                </td>
                                <td>
                                    {% if record.fee %}
                                        ¥{{ "%.2f"|format(record.fee) }}
                                    {% else %}
                                        -
                                    {% endif %}
                                </td>
                                <td>
                                    {% if record.exit_time %}
                                        {% if record.payment_status == 'paid' %}
                                            <span class="badge bg-success">已支付</span>
                                        {% else %}
                                            <span class="badge bg-warning">未支付</span>
                                        {% endif %}
                                    {% else %}
                                        <span class="badge bg-primary">使用中</span>
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        {% else %}
            <p class="text-center text-muted">暂无停车记录</p>
        {% endif %}
    </div>
</div>

<!-- 停车场信息 -->
<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">停车场信息</h5>
        <a href="{{ url_for('admin_parking_lots') }}" class="btn btn-sm btn-primary">管理停车场</a>
    </div>
    <div class="card-body">
        {% if parking_lots %}
            <div class="row">
                {% for lot in parking_lots %}
                    <div class="col-md-4 mb-3">
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title">{{ lot.name }}</h5>
                                <p class="card-text">
                                    <strong>地址：</strong> {{ lot.address }}<br>
                                    <strong>车位数：</strong> {{ lot.total_spaces }}<br>
                                    <strong>小时费率：</strong> ¥{{ "%.2f"|format(lot.hourly_rate) }}
                                </p>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% else %}
            <p class="text-center text-muted">暂未添加停车场</p>
        {% endif %}
    </div>
</div>
{% endblock %} 